/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package task02bt02;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author tanhung
 */
public class Bai01 {
   public void run()
   {
       String str;
       String sDuongDan;
       OutputStream f;
       System.out.println("Nhap chuoi du lieu muon ghi xuong file:");
       BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
       try {
           str = bf.readLine();
           System.out.println(str);
           System.out.println("Nhap duong dan cua tap tin muon luu:");
           sDuongDan = bf.readLine();
           System.out.println(sDuongDan);
           
           // tao output Stream object de luu xuong file
           f = new FileOutputStream(sDuongDan);
           
           //Chuyen cac dữ liệu đã nhập sang byte để lưu xuống FileOutputStream
           byte[] strBytes = str.getBytes();
           f.write(strBytes);
           
           System.out.println("Luu tap tin thanh cong!!");
           
       } catch (IOException ex) {
           Logger.getLogger(Bai01.class.getName()).log(Level.SEVERE, null, ex);
       }
   }
}
